#!/bin/sh

appdir=`pwd`

cd ..
parentdir=`pwd`
cd $appdir

JAVA_HOME=/opt/soft/jdk1.8
#JAVA_HOME=C:\Program Files\Java\jdk1.8.0_341
#JAVA_HOME=$parentdir/java/java_linux


APP_MAIN=xaytsc-common-rs-0.0.1-SNAPSHOT

tradePortalPID=0  
   
getTradeProtalPID(){  
    javaps=`$JAVA_HOME/bin/jps -l | grep -w $APP_MAIN`  
    if [ -n "$javaps" ]; then  
        tradePortalPID=`echo $javaps | awk '{print $1}'`  
    else  
        tradePortalPID=0  
    fi  
}  
  
shutdown(){  
    getTradeProtalPID  
    echo "============================================================================"  
    if [ $tradePortalPID -ne 0 ]; then  
        echo -n "Stopping $APP_MAIN(PID=$tradePortalPID)..."  
# 强制停机
#        kill -9 $tradePortalPID

# 优雅停机
	kill $tradePortalPID
	sleep 3
        if [ $? -eq 0 ]; then  
            echo "[Success]"  
            echo "===================================================================="  
        else  
            echo "[Failed]"  
            echo "===================================================================="  
        fi  
        getTradeProtalPID  
        if [ $tradePortalPID -ne 0 ]; then  
            shutdown  
        fi  
    else  
        echo "$APP_MAIN is not running"  
        echo "========================================================================="  
    fi  
}  
  
shutdown  